const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
// const webpack = require("webpack");

module.exports = {
  entry: path.resolve(__dirname, '../index.js'),
  devtool: 'eval',
  output: {
    path: path.resolve(__dirname, '../dist'),
  },
  resolve: {
    extensions: ['.jsx', '.js', '.ts', '.tsx'],
    alias: {},
  },

  module: {
    rules: [
      {
        test: /\.[tj]sx?$/,
        exclude: [path.resolve(__dirname, '../node_modules')],
        use: ['babel-loader'],
      },
    ],
  },
  optimization: {
    runtimeChunk: true,
    splitChunks: {
      chunks: 'all',
      // cacheGroups: {
      //   default: {
      //     minChunks: 2,
      //     priority: -20,
      //     reuseExistingChunk: true,
      //   },
      //   vendors: {
      //     test: /[\\/]node_modules[\\/]/,
      //     priority: -10,
      //   },
      // },
    },
  },

  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, '../public/index.html'),
      templateParameters: { PUBLIC_URL: 'public' },
    }),
    // new webpack.DefinePlugin({
    //   NODE_ENVIRONMENT: JSON.stringify("development"),
    // }),
    // new webpack.ProvidePlugin({
    //   _: ["./test.js", "default"],
    // }),
    new CopyWebpackPlugin({
      patterns: [
        { from: 'public/logo192.png', to: 'public' },
        { from: 'public/manifest.json', to: 'public' },
      ],
    }),
  ],
};
